package com.huangyi;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        // 测试用例
    }

    // 最长定差子序列
    static class Solution {
        public int longestSubsequence(int[] nums, int difference) {
            int n = nums.length;
            int[] dp = new int[n];
            Arrays.fill(dp, 1);

            for (int i = 1; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    if (nums[i] - nums[j] == difference) {
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                    }
                }
            }

            int ret = 1;
            for (int i = 0; i < n; i++) {
                ret = Math.max(ret, dp[i]);
            }
            return ret;
        }
    }
}